package com.supergdtop.www.run.SQLMethod;

import android.test.AndroidTestCase;
import android.util.Log;

import com.supergdtop.www.run.Vo.User;
import com.supergdtop.www.run.tools.DbOpenhelper;

import java.util.List;

/**
 * Created by chn10 on 2016/10/23.
 */

public class SqliteTest extends AndroidTestCase {
    public void testCreateSqllite()
    {
        DbOpenhelper db = new DbOpenhelper(this.getContext());
        // 第一次调用该方法会调用数据库  
        db.getWritableDatabase();
    }

    /**
     * 添加User  
     */
//    public void testSaveUser()
//    {
//        SQLUserService db = new SQLUserService(this.getContext());
//        User User = new User();
//        User.setName("LiMing");
//        User.setAmount(888);
//        db.addUser(User);
//
//    }

    public void addSaveUser(String username,String userphonenum ,String pwd)
    {
        SQLUserService db = new SQLUserService(this.getContext());
        User User = new User();
        User.setName(username);
        User.setPhonenumber(userphonenum);
        User.setPwd(pwd);
        db.addUser(User);

    }

    /**
     * 更新User  
     */
    public void UpdateUser(String username,String userphonenum ,String pwd)
    {
        SQLUserService db = new SQLUserService(this.getContext());
        User User = new User();
        User.setId(1);
        User.setName(username);
        User.setPhonenumber(userphonenum);
        User.setPwd(pwd);
        db.modifyUser(User);

    }

    /**
     * 删除User  
     */
    public void DeleteUser()
    {
        SQLUserService db = new SQLUserService(this.getContext());
        db.deleteUser(1);

    }

    /**
     * 查询一条User记录  
     */
    public void testUser()
    {
        SQLUserService db = new SQLUserService(this.getContext());
        User User = db.findUser(2);
        Log.i("SqliteTest", User.toString());

    }

    /**
     * 查询User集合对象  
     */
    public void testUserList()
    {
        SQLUserService db = new SQLUserService(this.getContext());
        List<User> Users = db.findUserList(0, 5);
        for (User parson : Users)
        {
            Log.i("SqliteTest", parson.toString());
        }

    }
    /**
     * 测试一个事务  
     */
    public void testgetTransaction(){
        SQLUserService db = new SQLUserService(this.getContext());
        String str = db.getTransaction();
        Log.i("SqliteTest", str);
    }
}
